window.onload = function (ev){
    setInterval(display,1000);
    var date = new Date();
    document.getElementById("date").innerHTML = date.getMonth()+1 +"月 "+ date.getFullYear()+"年";
    var today = date.getDate();
    date.setDate(1);//设置日期为当前月份的1号
    var firstDayWeekIndex = date.getDay();//这个月第一天是星期几
    date.setMonth(date.getMonth() + 1);
    var lastDate = new Date(date - 3600000*24);
    var allDay = lastDate.getDate();//总天数
    var num = 0;
    var trr = document.getElementById("line1");
    //第一行特殊处理
    for(var i = 0; i < 7; i++){
        var tdd = document.createElement("td");
        if(i >= Number(firstDayWeekIndex)){
            num++;
            if(num > allDay)
                tdd.innerHTML = "";
            else
                tdd.innerHTML = num;
            if(num == Number(today))
                tdd.style.backgroundColor="rgba(83, 83, 135, 0.5)";
        }
        trr.appendChild(tdd);
    }
    var lines = Math.ceil((allDay + firstDayWeekIndex)/7)//确定共几行
    for(var k = 1; k < lines; k++){
        trr = document.getElementById("line"+(k+1))
        for(var i = 0; i < 7; i++){
            var tdd = document.createElement("td");
            num++;
            if(num > allDay)
                tdd.innerHTML = "";
            else
                tdd.innerHTML = num;
            if(num == Number(today))
                tdd.style.backgroundColor="rgba(83, 83, 135, 0.5)";
            trr.appendChild(tdd);
        }
    }
}
function display(){
    var date = new Date();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    var end = " am";
    if(hour > 12){
        hour -= 12;
        end = " pm";
    }
    hour = (hour < 10)?"0"+hour:hour;
    minute = (minute < 10)?"0"+minute:minute;
    second = (second < 10)?"0"+second:second;
    document.getElementById("text").innerHTML = "现在是:"+hour+":"+minute+":"+second+end;
}